<?php
/*
 *  This file is part of Urd.
 *
 *  Urd is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *  Urd is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program. See the file "COPYING". If it does not
 *  exist, see <http://www.gnu.org/licenses/>.
 *
 * $LastChangedDate: 2008-07-10 23:59:20 +0200 (Thu, 10 Jul 2008) $
 * $Rev: 1285 $
 * $Author: gavinspearhead $
 * $Id: fatal_error.php 1285 2008-07-10 21:59:20Z gavinspearhead $
 */

if (!defined('ORIGINAL_PAGE')) die('This file cannot be accessed directly.');
$pathfe = realpath(dirname(__FILE__));
require_once "$pathfe/../functions/smarty.php";


function fatal_error($msg, $link=NULL, $link_msg=NULL)
{
	global $pathfe, $smarty, $LN;
	$smarty->assign('menu',		generate_menu($LN));
	$smarty->assign('title', 	$LN['fatal_error_title']);
	$smarty->assign('__message', array($msg));
	$smarty->assign('link', $link);
	$smarty->assign('link_msg', $link_msg);

	$smarty->display('fatal_error.tpl');

	die();
}


function near_fatal_error($msg, $ignore_name, $ignore_value=NULL, $link=NULL, $link_msg=NULL)
{ //used in browse for disk full check and timestamp check. In case the continue button is pressed, the $ignore_name has its value overwritten in the form and is then reposted
	global $pathfe, $smarty, $LN;
	$action = $_SERVER['REQUEST_URI']; // get the form name
	$cnt = 0;
	foreach ($_POST as $name=>$value){
		if ($name == $ignore_name) { 
			$cnt++;
			if ($ignore_value !== NULL) // replace the value with a new one; if null remove it
				$post[] = array ('name'=>$ignore_name, 'value' => $ignore_value);
		} else // other variables are copied
			$post[] = array('name'=>$name, 'value'=>$value);
	}
	if ($cnt == 0) // add it if it isn't part of the post yet
		$post[] = array ('name'=>$ignore_name, 'value' => $ignore_value);

	$smarty->assign('menu',		generate_menu($LN));
	$smarty->assign('title', 	$LN['fatal_error_title']);
	$smarty->assign('__message', array($msg));
	$smarty->assign('action', $action);
	$smarty->assign('link', $link);
	$smarty->assign('post', $post);
	$smarty->assign('link_msg', $link_msg);

	$smarty->display('fatal_error.tpl');
	die();
}


function semi_fatal_error($msg, $link=NULL, $link_msg=NULL)
{ // function is used for challenges that are too old; resets the challenge to a new value + resets the timeout
	global $pathfe, $smarty, $LN;
	$action = $_SERVER['REQUEST_URI']; // get the form name
	foreach ($_POST as $name=>$value){
		if ($name == 'challenge') 
			$post[] = array('name'=>'challenge', 'value'=>set_challenge());
		else 
			$post[] = array('name'=>$name, 'value'=>$value);
	}

	$smarty->assign('menu',		generate_menu($LN));
	$smarty->assign('title', 	'URD - ' . $LN['fatal_error_title']);
	$smarty->assign('__message', array($msg));
	$smarty->assign('action', $action);
	$smarty->assign('link', $link);
	$smarty->assign('post', $post);
	$smarty->assign('link_msg', $link_msg);
	$smarty->display('fatal_error.tpl');
	die();
}


?>
